package custom;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;


public class Quiz {
	
	private int quizId, authorId;
	private String name, desc;
	
	//konstruqtori
	public Quiz(String name,  int authorId, String desc, ArrayList<Question> list) throws SQLException{
		this.name = name;
		this.authorId = authorId;
		this.desc = desc;
//		ResultSet rs = QuizDBC.getInstance().selectFromQuizTable(-1,name, authorId, -1, -1);
//		quizId = rs.getInt("quizid");	
		quizId = 42;
	}
	
	public static Quiz RegisterQuiz(String name, int authorId, String desc, ArrayList<Question> list) throws SQLException{
//		QuizDBC.getInstance().insertIntoQuiz(name, authorId, desc, isOnePage, randSequence);
//		Quiz q = new Quiz(name, authorId, desc, new ArrayList<Question>());
//		return q;
		return new Quiz(name, authorId, desc, list);
	}

	public ArrayList<Question> getQuestionArrayList(){
		return new ArrayList<Question>();
	}
	
	public int getId(){
		return quizId;
	}
	
	
	//cxrilebtan gvaqvs problema!!!
	/**
	 * abrunebs useris sheqmnili quizebis veqtors
	 */
	public ArrayList<Quiz> createdQuizes(int userId, int sortBy) throws SQLException{
//		ResultSet rs = QuizDBC.getInstance().selectFromQuizTable(-1, "" , userId, sortBy ,-1);
//		ArrayList<Quiz> list = new ArrayList<Quiz>();
//		while(rs.next()){
//			Quiz q = new Quiz(rs.getString("name"), userId, rs.getString("desc"), rs.getInt("isonepage"), rs.getInt("randsequence"));
//			list.add(q);
//		}
//		return list;
		return null;
	}
	
	public void addQuestion(Question qst, int pos){
		
	}
	
	public int getQuestionsNumber(){
		return 0;
	}
	
	public String getName(){
		return name;
	}
	
	public String getDesc(){
		return desc;
	}
	
	public int getAuthor(){
		return authorId;
	}
	
	
	public String getNameHtml(){
		return "";
	}
	
	public static String getNameHtml(int id){
		return "";
	}
	
	//boloshi amatebs kitxvas
	public void append(Question qst){
		
	}
	
	public Performances [] getTop5EverPerformances() throws SQLException{
//		ResultSet rs = QuizDBC.getInstance().selectFromQuizescores(-1, quizId, 5, 0);
//		Performances [] per = new Performances[5];
//		int i = 0;
//		while(rs.next()){
//			Performances p = new Performances(quizId, rs.getInt("userid"), rs.getInt("score"));
//			per[i] = p;
//			i++;
//		}
//		return per;
		return new Performances[5];
	}
	
	public Performances [] getTop5TodayPerformances(){

		return new Performances[5];
	}
	
	public Performances [] getLast5Performances() throws SQLException{
//		ResultSet rs = QuizDBC.getInstance().selectFromQuizescores(-1, quizId, 5, 1);
//		Performances [] per = new Performances[5];
//		int i = 0;
//		while(rs.next()){
//			Performances p = new Performances(quizId, rs.getInt("userid"), rs.getInt("score"));
//			per[i] = p;
//			i++;
//		}
//		return per;
		return new Performances[5];
	}
	
	public ArrayList<Performances> getUserPerformances(int userId) throws SQLException{
	/*	ResultSet rs = QuizDBC.getInstance().selectFromQuizescores(userId, -1, 5, 1);
		ArrayList<Performances> list= new ArrayList<Performances>();
		while(rs.next()){
			Performances p = new Performances(rs.getInt("quizid"), userId, rs.getInt("score"));
			list.add(p);
		}
		return list;
	*/  return new ArrayList<Performances>() ;
	}
	
	public static Quiz getInstance(String name) throws SQLException{
		return new Quiz(name, 5, "qvizia ra ragitxra ...", null);
	}
	public static void removeQuiz(int id){
		
	}
	
	public static Quiz [] popular5() throws SQLException{
	/*	ResultSet rs = QuizDBC.getInstance().selectFromQuizTable(-1, "", -1, 2, 5);
		Quiz [] q = new Quiz[5];
		int i = 0;
		while(rs.next()){
			Quiz quiz = new Quiz(rs.getString("name"), rs.getInt("userid"), rs.getString("desc"), rs.getInt("isonepage"), rs.getInt("randsequence"));
			q[i] = quiz;
			i++;
		}
		return q;
	*/  return new Quiz [5] ;
	}
	
	public static Quiz [] recent5() throws SQLException{
	/*	ResultSet rs = QuizDBC.getInstance().selectFromQuizTable(-1, "", -1, 1, 5);
		Quiz [] q = new Quiz[5];
		int i = 0;
		while(rs.next()){
			Quiz quiz = new Quiz(rs.getString("name"), rs.getInt("userid"), rs.getString("desc"), rs.getInt("isonepage"), rs.getInt("randsequence"));
			q[i] = quiz;
			i++;
		}
		return q;
	*/  return new Quiz [5] ;
	}
	
	public static Quiz [] fiveBy(int userId) throws SQLException{
	/*	ResultSet rs = QuizDBC.getInstance().selectFromQuizTable(-1, "", userId, 2, 5);
		Quiz [] q = new Quiz[5];
		int i = 0;
		while(rs.next()){
			Quiz quiz = new Quiz(rs.getString("name"), userId, rs.getString("desc"), rs.getInt("isonepage"), rs.getInt("randsequence"));
			q[i] = quiz;
			i++;
		}
		return q;
	*/  return new Quiz[5] ;
	}
	
	public static boolean checkQuiz(String name) throws SQLException{
	/*	ResultSet rs = QuizDBC.getInstance().selectFromQuizTable(-1, name, -1, -1, -1);
		return rs.next();
	*/	return true;
	}
	
	public static ArrayList<Integer> getAllQuizzes() throws SQLException{
		/*ResultSet rs = QuizDBC.getInstance().selectFromQuizTable(-1, "", -1, -1, -1);
		ArrayList<Integer> list = new ArrayList<Integer>();
		while(rs.next()){
			list.add(rs.getInt("quizid"));
		}
		return list;
	*/  return new ArrayList<Integer>();	
	}
	
}
